var appPath = getAppPath();

$(function(){
	initJspGrid();
});

// 样版列表初始化
function initJspGrid(){
	
	$('#pointHisGrid').datagrid({
	    url:appPath + "/yjxOrders/pageGetPtsHisInfo.action",
	    height:'full',
	    striped:true,
	    fitColumns:true,
	    queryParams: getQueryParam(),
	    singleSelect:false,
	    selectOnCheck:true,
	    checkOnSelect:true,
//	    frozenColumns:[[
//	        {field:'ck',checkbox:'true',width:10,align:'center',sortable:false}
//	    ]],
	    columns:[[
  	        {field:'hisId',title:'积分记录ID',width:60,align:'center',sortable:false},
  	        {field:'userId',title:'用户ID',width:60,align:'center',sortable:false},
  	        {field:'curPts',title:'当前积分',width:60,align:'center',sortable:false,
	        	formatter:function(value, rowData, rowIndex){
	        		if (value){
	        			return '<span style="color:red">'+(value/100)+'</span>';
	        		}
	        		return '0';
	        	}
		    },
//  	        {field:'balFlg',title:'收支标记',width:80,align:'center',sortable:false,
//	        	formatter:function(value, rowData, rowIndex){
//	        		if (value){
//	        			switch(value){
//	        			case 0: return '<font color="ffff66">无效记录</font>';break;
//	        			case 1: return '<font color="red">添加积分</font>';break;
//	        			case 2: return '<font color="blue">消耗积分</font>';break;
//	        			}
//	        		}
//	        		return '未知';
//	        	}
//		    },
		    {field:'balPts',title:'收支积分额',width:60,align:'center',sortable:false,
	        	formatter:function(value, rowData, rowIndex){
	        		if (value){
	        			if (rowData.balFlg == 1){
	        				return '<span style="color:red">加:'+(value/100)+'</span>';
	        			} else if (rowData.balFlg == 2){
	        				return '<span style="color:blue">减:'+(value/100)+'</span>';
	        			} else {
	        				return '0';
	        			}
	        		}
	        		return '0';
	        	}
		    },
  	        {field:'orderId',title:'订单ID',width:80,align:'center',sortable:false,
		    	formatter:function(value,rowData,rowIndex){
		    		return value||'N/a';
		    	}
  	        },
  	        {field:'odrDtlType',title:'订单分类',width:80,align:'center',sortable:false,
  	        	formatter:function(value,rowData,rowIndex){
  	        		if (value){
  	        			switch(value){
  	        			case 2:return '<font color="#8B6914">去水印</font>';break;
  	        			case 4:return '<font color="#8B5F65">秒杀订单</font>';break;
  	        			case 8:return '<font color="#8B4C39">VIP订单</font>';break;
  	        			case 16:return '<font color="8B4513">充值订单</font>';break;
  	        			case 32:return '待定';break;
  	        			}
  	        		}
  	        		return '<font color="#969696">未知</font>';
  	        	}
  	        },
  	        {field:'odrDtlId',title:'子订单ID',width:80,align:'center',sortable:false,
  	        	formatter:function(value,rowData,rowIndex){
  	        		return value || 'N/a';
  	        	}
  	        },
  	        {field:'desc',title:'备注',width:100,align:'center',sortable:false},
	        {field:'createTime',title:'创建时间',width:70,align:'center',sortable:false},
	        {field:'updateTime',title:'更新时间',width:80,align:'center',sortable:false}
	    ]],
	    hideColumn:['user_type'],
	    pagination:true,
		rownumbers:true,
		toolbar:[
			/*{
				text:'标题',
				iconCls:'icon-cancel',
				handler:function(){
					delPrice();
				}
			}*/
			/*{
				text:'标题',
				iconCls:'icon-add',
				handler:function(){
					addPrice();
				}
			}*/		
		]
	});
}

function getQueryParam(){
	var queryObject = {};
	var findBalFlg = $("#queryBalFlg").combobox('getValue');// 积分标记
	var findOdrDtlType = $("#queryOdrDtlType").combobox('getValue');// 订单分类
	var findUserId = $("#queryUserId").val();// 用户ID
	var findOrderId = $("#queryOrderId").val();// 订单ID
	
	if(findBalFlg && Number(findBalFlg||'0')>0) queryObject.findBalFlg = findBalFlg;
	if(findOdrDtlType && Number(findOdrDtlType||'0')>0) queryObject.findOdrDtlType = findOdrDtlType;
	if(findUserId && Number(findUserId)>0) queryObject.findUserId = findUserId;
	if (findOrderId && Number(findOrderId)>0)queryObject.findOrderId = findOrderId;
	return queryObject;
}

function doQuery(){
	$("#pointHisGrid").datagrid('unselectAll');
	$("#pointHisGrid").datagrid('load', getQueryParam());
}
